package com.anlu.base.common.core.util;

import org.springframework.context.MessageSource;

import java.util.Locale;

public class MsgUtils {
    /**
     * 通过code 获取中文错误信息
     * @param code
     * @return
     */
    public String getMessage(String code){
        MessageSource messageSource = SpringContextHolder.getBean(MessageSource.class);
        return messageSource.getMessage(code,null, Locale.CHINA);
    }


    public String getMessage(String code,Object...args){
        MessageSource messageSource = SpringContextHolder.getBean(MessageSource.class);
        return messageSource.getMessage(code,args, Locale.CHINA);
    }

    /**
     * security 通过code 和参数获取中文错误信息
     * @param code
     * @return
     */
    public String getSecurityMessage(String code, Object... objects) {
        MessageSource messageSource = SpringContextHolder.getBean("securityMessageSource");
        return messageSource.getMessage(code, objects, Locale.CHINA);
    }


}
